<template>
  <div class="home-page">
    <div class="banner">
      <div class="container">
        <h1 class="logo-font">conduit</h1>
        <p>A place to share your knowledge.</p>
      </div>
    </div>

    <div class="container page">
      <div class="row">
        <div class="col-md-9">
          <div class="feed-toggle">
            <ul class="nav nav-pills outline-active">
              <li class="nav-item">
                <a class="nav-link disabled" href>Your Feed</a>
              </li>
              <li class="nav-item">
                <a class="nav-link active" href>Global Feed</a>
              </li>
            </ul>
          </div>

          <div v-for="item in articles" :key="item.slug" class="article-preview">
            <div class="article-meta">
              <a href="profile.html">
                <img :src="item.author.image" />
              </a>
              <div class="info">
                <a href class="author">{{item.author.username}}</a>
                <span class="date">{{item.createdAt}}</span>
              </div>
              <button class="btn btn-outline-primary btn-sm pull-xs-right">
                <i class="ion-heart"></i>
                {{item.favoritesCount}}
              </button>
            </div>
            <a href class="preview-link">
              <h1>{{item.title}}</h1>
              <p>{{item.body}}</p>
              <span>Read more...</span>
            </a>
          </div>
        </div>

        <div class="col-md-3">
          <div class="sidebar">
            <p>Popular Tags</p>

            <div class="tag-list">
              <a v-for="item in tags" :key="item" href class="tag-pill tag-default">{{item}}</a>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getArticles } from '@/api/article'
import { getTags } from '@/api/tag'
export default {
  name: 'HomeIndex',
  async asyncData() {
    const { data } = await getArticles()
    const { data: tagData } = await getTags()

    return {
      articles: data.articles,
      tags: tagData.tags
    }
  }
}
</script>